<template>
  <rx-layout>
      <div slot="left" width="200" showButton="true">
          <rx-fit>
              <rx-category-treeeditor
                  cat-key="BPM"
                  :statisticConfig="statisticConfig"
                  read-key="inst.read"
                  :edit="false"
                  @handSelect="selectTreeNode"
                  :async="true"
                  v-if="isShowManageTree"
                  :isAdmin="isManageToTree"
                  :treeRootList="treeRootList"
                  :isBpmClient="isMyBpmClient"
                  :isMyBpm="isMyBpmClient"
              ></rx-category-treeeditor>
          </rx-fit>
      </div>
    <div slot="center">
      <rx-fit :isheader="isheader">
          <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <rx-list-title :title="i18n('list.forwardTask','我的抄送')"></rx-list-title>
           <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
            </span>
          </div>
          <div  btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="resetSearch" @close="closeSearchbar">
              <a-form :layout="colLayout">
                  <a-row :gutter="24">
                      <a-col :span="colSpan">
                          <a-form-item :label="i18n('form.billNo','单号')">
                              <a-input :placeholder="i18n('form.billNo','单号','input')" v-model="queryParam['Q_BILL_NO__S_EQ']" />
                          </a-form-item>
                      </a-col>
                      <a-col :span="colSpan">
                          <a-form-item :label="i18n('form.itemTitle','事项标题')">
                              <a-input :placeholder="i18n('form.itemTitle','事项标题','input')" v-model="queryParam.Q_SUBJECT__S_LK" />
                          </a-form-item>
                      </a-col>
                      <a-col :span="colSpan" v-if="!curApp.appId">
                          <a-form-item :label="$ti18('rxForm.appId', '应用')">
                              <rx-search-app @change="appChange" v-model="searchApps">
                              </rx-search-app>
                          </a-form-item>
                      </a-col>
                  </a-row>
              </a-form>
          </div>
        <rx-grid
          ref="table"
          v-if="isShowManageTree"
          :bordered="isBorder"
          :allowRowSelect="false"
          :multiSelect="true"
          :columns="columns"
          :defaultPageSize="10"
          url="/api-bpm/bpm/core/bpmInstCc/getMyTurnTo"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10','30','40']"
          id-field="taskId"
          :loadDataOnstart="true"
          @selectChange="onSelectChange"
          @getListData="loadDataAgen"
        >
          <span slot="ccType" slot-scope="{text,record}" >
            <a-tag :color="typeMap[text].color">
              <span>{{typeMap[text].text}}</span>
            </a-tag>
          </span>
            <span slot="appId" slot-scope="{ text, record }">
                {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
            </span>
            <span slot="billNo" slot-scope="{ text, record, index }">
                {{ record.billNo }}
            </span>
                    <span slot="action" slot-scope="{text, record}" class="actionIcons">
              <span @click="onDetail(record)" :title="$ti18('rxList.detailBtn','明细')">{{$ti18('rxList.detailBtn','明细')}}</span>
            <template >
              <span @click="showCcInfo(record)" :title="i18n('list.reading','阅读情况')">{{i18n('list.reading','阅读情况')}}</span>
            </template>
          </span>
        </rx-grid>
      </rx-fit>
      <bpm-instcc-detail :inst-id="instId" :inst-cc-show.sync="instCcShow" ></bpm-instcc-detail>

    </div>
  </rx-layout>
</template>


<script>
    import Vue from 'vue';
    import { AppBaseList, RxLayout,Util,RxFit,RxGrid } from '@lowcode/jpaas-common-lib'
    import RxCategoryTreeeditor from "@/components/redxun/rx-category-treeeditor";
    import BpmInstCcDetail from '@/views/modules/bpm/core/BpmInstCcDetail'
    import FlowUtil from "../js/FlowUtil";
    import {mapState} from 'vuex';
    import AppSearch from "@/views/modules/share/AppSearch";
    import RxSearchApp from "@/views/modules/share/rx-search-app";
    import instAndTaskShare from "@/views/modules/bpm/core/js/instAndTaskShare";

    Vue.component("bpm-instcc-detail",BpmInstCcDetail)


    export default {
        name: 'my-receive-task',
        mixins: [AppBaseList,instAndTaskShare,FlowUtil,AppSearch],
        components: {
            RxLayout,
            RxFit,
            RxGrid,
            RxCategoryTreeeditor,
            RxSearchApp
        },
        computed: {
            ...mapState({
                // 所属应用
                allApps: state => state.appSetting ? state.appSetting.allApps : {}
            }),
        },
        data() {
            return {
                instId:'',
                instCcShow:false,
                // 表头
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type:'indexColumn',
                        dataIndex:'serial',
                        scopedSlots: { customRender: 'serial' },
                        width: 60
                    },

                    {
                        title: this.i18n('form.itemTitle','事项标题'),
                        dataIndex: 'subject',
                        width:200,
                        ellipsis:false,
                    },
                    {
                        title: this.i18n('form.billNo','业务单号'),
                        dataIndex: 'billNo',
                        scopedSlots: { customRender: 'billNo' },
                        width: 180,
                        ellipsis: false,
                    },
                    {
                        title: this.i18n('form.nodeName','转发节点'),
                        dataIndex: 'nodeName',
                        width:120,

                    },
                    {
                        title: this.i18n('form.createTime','转发时间'),
                        dataIndex: 'createTime',
                        width:140
                    },
                    {
                        title: this.i18n('form.ccType','转发/抄送'),
                        dataIndex: 'ccType',
                        width:80,
                        scopedSlots: { customRender: 'ccType' },
                    },
                    {
                        title: this.i18n('form.appId','所属应用'),
                        dataIndex: 'appId',
                        width: 140,
                        sortField: 'APP_ID_',
                        scopedSlots: {customRender: 'appId'}
                    },
                    {
                        title: this.$ti18('rxList.action','操作'),
                        dataIndex: 'action',
                        fixed:'right',
                        width:100,
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                typeMap: {
                    "COPY": { color: 'green', text: this.i18n('typeMap.cc','抄送') },
                    "TURN_TO": { color: 'red', text: this.i18n('typeMap.forward','转发') },
                },
                statisticConfig: {
                    type:"static_bpm",
                    table:"BPM_INST_CC",
                    field:"TREE_ID_",
                    whereConf:[{name:"FROM_USER_ID_",type:"string",dateFormat:"",op:"=",value:"curUserId",valueType:"context"}]
                },
                //应用列表
                appList:[],
                loading:false,
                //选择的应用
                selectedApp:[],
                isMyBpmClient:true,
                readKey:"task.read",
                readType:"instCcHist",
                isInit:true
            }
        },
        methods: {
            i18n(name,text,key){
                return this.$ti18(name,text,"MyTurnTo",key);
            },
            selectTreeNode(curRow) {
                this.loadDataBySelectTreeNode(curRow);
            },
            onDetail(record){
                this.openDetail(record.appId,record.instId);
            },
            showCcInfo(record){
                this.instId=record.instId;
                this.instCcShow=true;
            },
            closeSearchbar(){
                //关闭过滤弹窗；（点击X触发）
                this.fitSearch = false ;
            },
            resetSearch(){
                this.appChange("")
                this.cancel()
            }
        }
    }
</script>
<style scoped>

</style>

